package com.polaris.live.utils.image

import android.content.Context
import android.graphics.drawable.Drawable
import android.util.Log
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory
import com.polaris.live.utils.file.FileUtils
import java.io.File

/**
 * glide配置
 *
 * @author Created by lucas on 2023/10/26 20:24
 * @since 1.0.0
 */
@GlideModule
class MyGlideModel : AppGlideModule() {

    override fun applyOptions(context: Context, builder: GlideBuilder) {
        builder
            .setLogLevel(Log.ERROR)
            .setDefaultTransitionOptions(
                Drawable::class.java, DrawableTransitionOptions.withCrossFade(
                    DrawableCrossFadeFactory.Builder()
                        .setCrossFadeEnabled(true)
                        .build()
                )
            )
            .setDiskCache {
                DiskLruCacheWrapper.create(
                    File(FileUtils.getImageCacheDir()),
                    300L * 1024L * 1024L
                )
            }
    }
}